<?php

class DB_Functions {

	private $db;
	
	function __construct() {
		
	}
	
	public function getConTicker() {
		include_once 'DB_Connect.php';
		$con = new DB_Connect();
		$this->db = $con->connectTicker();
	}
	
	public function getConWordpress() {
		include_once 'DB_Connect.php';
		$con = new DB_Connect();
		$this->db = $con->connectWordpress();
	}
	
	public function getMatch() {
		$this->getConTicker();
		$sqlmatch = 'SELECT * FROM liveticker_match WHERE active=1;';
		$resultmatch = $this->db->query($sqlmatch);
		if (!$resultmatch) {
			die ('Etwas stimmte mit dem Query nicht: '.$db->error);
		}
		$this->db->close();
		return $resultmatch;
	}
	
	public function getEntries($eidi)
	{
		$this->getConTicker();
		$sqlentry = 'SELECT * FROM liveticker_entry WHERE match_id='.$eidi.';';
		$resultentry = $this->db->query($sqlentry);
		if (!$resultentry) {
			die ('Etwas stimmte mit dem Query nicht: '.$db->error);
		}
		$this->db->close();
		return $resultentry;
	}
	
	public function getNews() {
		$this->getConWordpress();
		$sqlnews = 'SELECT * FROM wp_posts WHERE post_status=\'publish\';';
		$resultnews = $this->db->query($sqlnews);
		if (!$resultnews) {
			die ('Etwas stimmte mit dem Query nicht: '.$db->error);
		}
		$this->db->close();
		return $resultnews;
	}
	
	public function closeResult() {
		$result->close();
		unset($result);
	}
}
?>